#include <iostream>
#include <pthread.h>
#include <unistd.h>

void* Routine(void* arg)
{
  int i = (long)arg;
  while(true){
    printf("I am %d thread\n", i);
    sleep(1);
  }
}

int main()
{
  pthread_t tids[3];
  for(long i = 0; i < 3; i++){
    pthread_create(&tids[i], nullptr, Routine, (void*)i);
  }

  int i = 0;
  while(true){
    sleep(1);
    if(i++ == 2){
      pthread_cancel(tids[2]);
      printf("thread 3 quit...\n");
    }
  }
  return 0;
}
